package com.globallogic.jbtask3;

public class AnagramUtil {

    private static final int ARRAY_SIZE = 26;
    private static final int CHAR_BASE = 65;
    
    private static int[] getCharCodeArray(String string) {
        
        int charCodes[] = new int[ARRAY_SIZE];
        int code;

        for (int i = 0; i < string.length(); i++) {

            code = ((int) string.charAt(i)) - CHAR_BASE;

            if (code > 0) {
                charCodes[code]++;
            }
            
        }

        return charCodes;
  
    }   
   
    public static boolean isAnagram(String string1, String string2) {
        

        int[] charCodes1;
        int[] charCodes2; 
 
        string1 = string1.toUpperCase();
        string2 = string2.toUpperCase();

        charCodes1 = getCharCodeArray(string1); 
        charCodes2 = getCharCodeArray(string2); 

        for (int i = 0; i < ARRAY_SIZE; i++) {
        
            if (charCodes1[i] != charCodes2[i]) {

               return false;

            }            

        }

        return true;
    }
}